<?php

namespace Admin\Controller;





class LinkController extends BaseController {
    //文章分类显示
    public function lst(){
            $Link=M('Link');
            $map['state']=1;
            $link=$Link->where($map)->select();
            $this->assign('link',$link);
            $this->display();
        
    }
    
    
    //文章分类添加
    public function ad(){
        
            $Link = M('Link');
                    
            if (IS_POST){
                $data = array(
                    'company' => I('company'), 
                    'company_url' => I('url'),
                    'status' => I('status'),
                    'createtime' => time(),
                );
                if ($Link->create($data)){
                    if ($Link->add()){
                        $this->success('新增成功',U('lst'));
                    }else {
                        $this->error('新增失败！');
                    }
                }else {
                    $this->error($Link->getError());
                }
                return ;
            }  

            $this->display();
        
    }

    
    
    
    public function edt($id){
        
            $Link = M('Link');
            $link=$Link->find($id);
            $this->assign('link',$link);
            if (IS_POST){
                $data =array(
                    'id'=>I('id'),
                    'company'=>I('company'),
                    'company_url'=>I('url'),
                    'state'=>I('state'),
                    'createtime'=>time(),
                );
                if ($Link->create($data)){
                    if ($Link->save()){
                        $this->success('修改成功',U('lst'));
                    }else {
                        $this->error('修改失败！');
                    }
                }else {
                    $this->error($Link->getError());
                }
                
                return ;
            }
            
            
            $this->display();
        
        
        
    } 
    
    
    
    //文章单删除
    public function del($id){
        
                 $Link = M('Link');
            if ($Link->delete($id)){
                $this->success('删除成功！',U('lst'));
            }else {
                $this->error('删除失败');
            }
        

    }
    //全部删除
    public function del_both(){
        
            $del_both = I('del_both');
            if ($del_both!==""){
                $del_id =implode(',', $del_both);
                $Article_cat =D('Article_cat');
                if ($Article_cat->delete($del_id)){
                    $this->success('删除成功！',U('lst'));
                }else {
                    $this->error('删除失败');
                }
            }
       
        
    }

   
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
}